<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正在拨打</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-between;
            height: 100vh;
            margin: 0;
            background-color: #f4f4f4;
        }

        .contact-info {
            margin-top: 50px;
            text-align: center;
        }

        .contact-info h1 {
            margin: 0;
            font-size: 36px;
        }

        .contact-info p {
            margin: 10px 0 0;
            font-size: 24px;
            color: #555;
        }

        .hangup-button {
            width: 100%;
            max-width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #f44336;
            color: white;
            border: none;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            cursor: pointer;
            margin-bottom: 50px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .hangup-button:active {
            background-color: #e53935;
        }

        h1 {
            color: rgb(92, 220, 147);
        }
    </style>
</head>

<body>
    <div class="contact-info">
        <h1 id="bohao">正在通话中。。。</h1>
        <h2 id="contact-name">未知联系人</h2>
        <p id="contact-number">未知号码</p>
    </div>
    <button class="hangup-button" onclick="back('call')">挂机</button>

    <script>
        window.addEventListener('message', function (event) {
            if (event.data.action === 'setContact') {
                const { name, number } = event.data;
                console.log(name);
                console.log(number);


                if (number !== undefined) {
                    document.getElementById('contact-name').textContent = name;
                    document.getElementById('contact-number').textContent = number;

                    fetch(`http://127.0.0.1:8080/operation=call`, {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify({ number })
                    });
                } else {
                    document.getElementById('contact-name').textContent = "";
                    document.getElementById('contact-number').textContent = number;
                    console.log('未知用户或号码');
                }
            }
        });
        function back(page) {
            alert('电话已挂断');
            window.parent.postMessage({ action: 'loadPage', page: page }, '*');
        }

    </script>
</body>

</html>